const db=require('../db/index.js')
const payPrice=(req,res)=>{
    const {userId,price}=req.body;
    if(!userId||!price) return res.send({status:500,message:'参数不完全'})
    const price1=Number(price)
    db.query("select price from new_users where id=?",[userId],function(err,result){
      if (err) {
        return res.send({ status: 500, message: '付款失败' });
      }
        else{
            if(price1>result[0].price) return res.send({status:500,message:'余额不足'})
              else{
                let price = result[0].price - price1;
                db.query("update new_users set price=? where id=?",[price,userId],function(err,result){
                    if(err) return res.send({status:500,message:'付款失败'})
                      else return res.send({status:200,message:'付款成功',data:price})
                })
              }
        }
    })
}
module.exports={
    payPrice
}